<?php
/**
 * 支付插件中间层实现类
 * @package App
 * @subpackage  Driver
 * @author cjli
 *
 */
class Payment
{
	/**
   * 支付方式信息
   * @var array
   */
  protected $_paymentInfo;

  /**
  * 取得支付类实例
  * @static
  * @access public
  * @return mixed
  */
  static function getInstance() {
  	$param = func_get_args();
    return get_instance_of(__CLASS__,'factory',$param);
  }
  
  /**
     * 加载支付接口文件并实例化
     * @access public
     * @param string $payment 支付接口名称
     * @return string
     */
    public function factory( $paymentname = '' ) {
    	$paymentDir = LIBRARY_PATH . 'COM/Payment/';
    	$paymentname  = strtolower(trim($paymentname));
      $class = ucwords($paymentname);
    	$paymentFile = $paymentDir.$class.'/'.$class.'.php';
    	if(!is_file($paymentFile)){
    		 // 文件不存在
        throw_exception(L('_PAYMENT_FILE_DOES_NOT_EXIST_').': ' . $paymentFile);
    	}else{
    		require $paymentFile;
	    	if(class_exists($class)){
	    		$payment = new $class();
	    	}else{
	    		// 类没有定义
	    		throw_exception(L('_PAYMENT_CLASS_DOES_NOT_DEFINE_').': ' . $paymentFile);
	    	}
    	}
    	return $payment;
    }

  /**
   * 获取配置
   * @return array
   */
  protected function getSettingFields(){}

  /**
   * 获取提交表单
   * @param mixed $set
   * @return string
   */
  protected function getSubmitForm($info){}
}

interface Payment_Interface
{
  /**
   * 页面回调
   */
  public function callback();
}

interface Payment_Server_Interface
{
  /**
   * 服务器回调
   */
  public function serverCallback();
}
